﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MobilePlugin.Core;
using MobilePulginBase;

namespace StartUp.Dialog
{
    public partial class FrmMain : Form
    {
        private PluginManager manager;
        private ImageList imageList;
        private Dictionary<string, IPlugin> plist;
        public FrmMain()
        {
            InitializeComponent();
            manager = PluginManager.GetInstance;
            plist = manager.GetPlugins();
            imageList = new ImageList();
            imageList.ImageSize = new Size(30, 30);
            listView1.LargeImageList = imageList;
            foreach (IPlugin p in plist.Values)
            {
                imageList.Images.Add(p.Icon);
                ListViewItem item = new ListViewItem();
                item.Text = p.Caption;
                item.ImageIndex = p.Index - 1;
                item.Tag = p.Name;
                listView1.Items.Add(item);
            }

         ;
            
        }

        private void listView1_ItemActivate(object sender, EventArgs e)
        {
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Selected)
                {
                    IPlugin p = manager.FindPlugin(listView1.Items[i].Tag.ToString());
                    if (p != null)
                    {
                        p.ShowUIForm(this.Owner, null);
                    }
                }
            }
        }
    }
}